on Command
Invoked when a command is received by a component this listener is registered with.
Implementers should typically use a switch statement or if-else-if chain on the name} parameter to identify the command and then process it accordingly, using the arg} parameter if provided.
The specific set of command names and the expected format or meaning of their arguments are defined by the system or component issuing the commands. Refer to the relevant documentation for available commands and their usage.
Example command handling:
*public void onCommand(String name, String arg) {
if ("RESTART_PLAYER".equalsIgnoreCase(name)) {
// Code to restart the player
} else if ("SET_VOLUME".equalsIgnoreCase(name)) {
try {
int volumeLevel = Integer.parseInt(arg);
// Code to set player volume
} catch (NumberFormatException e) {
// Log error: invalid volume argument
}
} else if ("NAVIGATE_TO".equalsIgnoreCase(name)) {
// Code to navigate to a screen or URL specified in 'arg'
} else {
// Log: unhandled command
}
}
This method constructs and executes a JavaScript snippet that attempts to call a function named RevelDigital.Controller.onCommand(name, value) within the context of the currently loaded page in the WebView. Before execution, the name and value parameters are sanitized by escaping single quotes (') to prevent JavaScript string termination and potential injection vulnerabilities.
The JavaScript checks for the existence of RevelDigital.Controller.onCommand before attempting to call it. If the function is not found, a warning is logged to the JavaScript console.
Parameters
The name of the command to be passed to the JavaScript function. If null, it will be treated as an empty string. Single quotes will be escaped.
The value associated with the command, also passed to the JavaScript function. If null, it will be treated as an empty string. Single quotes will be escaped.